﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceManager.Utils;

namespace QuotationService.RealtimeQuotation
{
    public class ETFQuotationRepository
    {
        private static ETFEntityConverter etfEntityConverter = new ETFEntityConverter();

        #region 基本信息操作
        /// <summary>
        /// 更新单个商品的基本信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <param name="basicInfo"></param>
        /// <returns></returns>
        public static bool UpdateBasicInfo(string quotSource, Quotation.ETF.BasicInfo basicInfo)
        {
            ETFBasicInfo etfBasicInfo = etfEntityConverter.Convert(basicInfo);
            byte[] bytes = etfBasicInfo.ObjectToBytes();
            return BasicInfoChannel.Update(quotSource, etfBasicInfo.Code, bytes);
        }
        /// <summary>
        /// 获取单个商品的基本信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static Quotation.ETF.BasicInfo GetBasicInfo(string quotSource, string code)
        {
            var bytes = BasicInfoChannel.Get(quotSource, code);
            ETFBasicInfo etfBasicInfo = StructHelper.BytesToObject<ETFBasicInfo>(bytes);
            return etfEntityConverter.Convert(etfBasicInfo);
        }
        /// <summary>
        /// 获取全部商品的基本信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <returns></returns>
        public static List<Quotation.ETF.BasicInfo> GetAllBasicInfo(string quotSource)
        {
            var allBasicInfoBytes = BasicInfoChannel.GetAll(quotSource);
            List<Quotation.ETF.BasicInfo> rtn = new List<Quotation.ETF.BasicInfo>();
            foreach (byte[] bytes in allBasicInfoBytes)
            {
                ETFBasicInfo etfBasicInfo = StructHelper.BytesToObject<ETFBasicInfo>(bytes);
                rtn.Add(etfEntityConverter.Convert(etfBasicInfo));
            }
            return rtn;
        }
        /// <summary>
        /// 清除单个商品的基本信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public static bool ClearBasicInfo(string quotSource, string code)
        {
            return BasicInfoChannel.Clear(quotSource, code);
        }
        /// <summary>
        /// 清除全部商品的基本信息
        /// </summary>
        /// <param name="quotSource"></param>
        /// <returns></returns>
        public static bool ClearAllBasicInfo(string quotSource)
        {
            return BasicInfoChannel.Clear(quotSource);
        }
        #endregion

    }
}
